﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using sieuthi.Threelayer.BUS;
using sieuthi.Threelayer.VO;
namespace sieuthi
{
    public partial class _user_login : Form
    {
        
        private SqlDataAdapter da = new SqlDataAdapter();
        private SqlCommand cmd = new SqlCommand();
        private SqlConnection conn = new SqlConnection(Threelayer.VO.core.connectionsring.ToString());
        private DataTable dt = new System.Data.DataTable();
        loginVO _UserVO = new loginVO();
        UserBUS _UserBUS = new UserBUS();
        public _user_login()
        {
            InitializeComponent();
            AcceptButton = buttonX1;
            ID.Text = "lethinh";
            password.Text = "thinh123";
        }

        private void buttonX1_Click(object sender, EventArgs e)
        {
            try
            {
                if (ID != null)
                {
                    string ten = ID.Text;
                    string pass = password.Text;
                    bool kq =  cheklogin(ten,pass);
                    if (kq == true)
                    {
                        this.Hide();
                        
                        macdinh _cs = new macdinh();
                        _cs.Show();
                    }
                    else
                        if (kq == false)
                        {
                            MessageBox.Show("LỖi ĐĂNG NHẬP","LOI",MessageBoxButtons.OK);
                        }
                }
                
            }
            catch
            {
            }

            
        }
        private bool cheklogin( string ID, string password)
        {
            cmd.Connection = conn;
            cmd.CommandType = CommandType.StoredProcedure;
            conn.Open();
            cmd.CommandText = "user_dangnhap";
            cmd.Parameters.Add("@ID", SqlDbType.NVarChar, 200).Value = ID.ToString();
            cmd.Parameters.Add("@Password", SqlDbType.NVarChar, 200).Value = password.ToString();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            SqlDataReader reader = cmd.ExecuteReader();
            if (reader.Read() == true)
            {
                return true;
            }
            else
                return false;
        }
        private void _user_login_Load(object sender, EventArgs e)
        {
            
        }
    }
}
